package com.zq.it.action.admin;

import java.util.List;

import javax.annotation.Resource;

import com.zq.it.action.BaseAction;
import com.zq.it.pojo.Academy;
import com.zq.it.service.admin.AcademyService;
import com.zq.it.tool.Constant;
import com.zq.it.tool.EtyLsName;
import com.zq.it.tool.FileName;
import com.zq.it.tool.FileType;
import com.zq.it.tool.HeadTitle;

import net.sf.json.JSONArray;
public class AcademyAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	@Resource
	private AcademyService academyService;	
	private Academy academy;
	private String type;
	private int [] acmyGroupId;	
	private String param;
	
	public void searchAcmyList(){
		
		List list=academyService.getAllAcademy();
		uploadList(EtyLsName.ACMY_LS.name(),list);				
	    print(JSONArray.fromObject(list,Constant.getJcf("YYYY-MM-dd")).toString(),"UTF-8","APPLICATION/JSON");
	}
	public void searchAcmyListFromType(){
		
		List list=academyService.getAcademyListByType(type, param);
		uploadList(EtyLsName.ACMY_LS.name(),list);			
		print(JSONArray.fromObject(list,Constant.getJcf("YYYY-MM-dd")).toString(),"UTF-8","APPLICATION/JSON");
	}
	
	public void deleteAcmyGroups(){
		academyService.removeAllAcademy(acmyGroupId,(List<Academy>)getHttpSession().getAttribute(EtyLsName.ACMY_LS.name()));
		 print("已删除"+acmyGroupId.length+"条记录！","UTF-8","text/html");
	}
	public void addAcmyPo(){
		academyService.addAcademy(academy);
		print("<script>parent.closeWindow('已添加');</script>","UTF-8","text/html");	
	}
	public void modifyAcmyPo(){
		academyService.renewalAcademy(academy);
		print("<script>parent.closeWindow('已修改！');</script>","UTF-8","text/html");	
	}
	public void importAcmyList(){	
		String msgStr="";
		List<Academy> list=academyService.importAcademyList(getUpload());
		if(list.size()>0){
		 getRequest().getSession().setAttribute("existAcmyList",list);	
		 msgStr="existList";
		}else{
			msgStr="已导入成功!";
		}
		print("<script>parent.importBackResult('"+msgStr+"','webpage/adminpage/academy/aexisAcmy.jsp');</script>","UTF-8","TEXT/HTML");
	}
	public void exportAcmyList(){				
		download(academyService.exportAcademyList(HeadTitle.CN_ACMYHEAD.getArray(),(List<Academy>)getHttpSession().getAttribute(EtyLsName.ACMY_LS.name())),FileName.ACMY_LIST_NAME.toString()+FileType.XLSX);
	}
	
	public Academy getAcademy(){
		return academy;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getParam() {
		return param;
	}
	public void setParam(String param) {
		this.param = param;
	}
	public void setAcademy(Academy academy){
		this.academy = academy;
	}
	public void addAcmy() {
		academyService.addAcademy(academy);
		
	}
	public int[] getAcmyGroupId() {
		return acmyGroupId;
	}
	public void setAcmyGroupId(int[] acmyGroupId) {
		this.acmyGroupId = acmyGroupId;
	}
	public void deleteAcademy(){
		academyService.removeAcademy(academy);
	}
}
